package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.user.PickCompanyListEntity;
import com.sgb.kjwl.view.widget.RoundImageView;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PickCompanyListAdapter extends BaseRecycleAdapter<PickCompanyListEntity> {

    private CallBack mCallBack;

    public PickCompanyListAdapter(Context context, List<PickCompanyListEntity> datas,CallBack callBack) {
        super(context, R.layout.item_pick_company, datas);
        this.mCallBack = callBack;
    }

    @Override
    public void convert(ItemViewHolder holder, final PickCompanyListEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        RoundImageView roundImageView = holder.getItem().findViewById(R.id.iv_logo);
        TextView textFocus = holder.getItem().findViewById(R.id.text_Focus);

        if(entity.getFocus()){
            textFocus.setBackgroundResource(R.drawable.focus);
        }else{
            textFocus.setBackgroundResource(R.drawable.unfocus);
        }

        if(TextUtils.isEmpty(entity.getLogo()) || "".equals(entity.getLogo())){
            roundImageView.setBackground(context.getResources().getDrawable(R.drawable.pick_company));
        }

    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.getItem().findViewById(R.id.text_Focus).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.onItemFocus(datas.get(position), position);
            }
        });
    }

    public interface CallBack{
        void onItemFocus(PickCompanyListEntity entity, int view);
    }
}
